//
//  BaseTableViewController.swift
//  SinaWeibo
//
//  Created by NeXTSTEP on 15/9/30.
//  Copyright © 2015年 NeXTSTEP. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VistorLoginViewDelegate {

    //定义标记变量 标记用户是否登录
    var userLogin = UserAccount.shareUserAccount != nil
    var vistorLoginView: VisitorLoginView?
    
    //苹果专门为了手写代码提供的方法  一旦实现了此方法  xib / storyboadr 会自动失效
    //执行此方法会自动检测根视图控制器是否被实例化 如果没有被实例化 会执行该方法
    //在视图没有初始化之前 不要跟踪
    override func loadView() {
        if userLogin {
            super.loadView()
            return
        }
        
                UINavigationBar.appearance().tintColor = UIColor.orangeColor()

        //实例化一个自定义视图
        vistorLoginView = NSBundle.mainBundle().loadNibNamed("VisitorLoginView", owner: nil, options: nil).last as? VisitorLoginView
        vistorLoginView?.vistorViewDelegate = self
        view = vistorLoginView
        
        //添加顶部barbutton
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginBtnDidClick")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerBtnDidClick")

    }
    
    @objc func loginBtnDidClick() {
        print(__FUNCTION__)
        
        let sb = UIStoryboard(name: "OAuth", bundle: nil)
        let VC = sb.instantiateInitialViewController() as! UINavigationController
        presentViewController(VC, animated: true, completion: nil)
    }
    
    @objc func registerBtnDidClick() {
        print(__FUNCTION__)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}
